package com.example.deploysinggle.test1.common.enums;

import com.example.deploysinggle.test1.common.exeptions.BizException;
import com.example.deploysinggle.test1.common.util.AbstractSyncDataService;
import com.example.deploysinggle.test1.common.util.SpringUtil;
import com.example.deploysinggle.test1.interface1.ABC;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2024/12/26 11:50
 */
@Getter
@AllArgsConstructor
public enum SyncDatEnum
{
    //使用先判断 datetype 是啥就执行同步哪个数据
    GET_HR("HR", "hr", "hr11", ABC.Aa.class, ABC.class),
    GET_OA("OA", "oa", "oa11", ABC.Aa.class, ABC.class),
    GET_NULL("OTHERS", "others", "null11", null, null)
    ;
    private String source;

    private String templateType;

    private String dataType;

    private Class<ABC.Aa> className;
   //调用的类
    private Class disPoseClass;

    public static AbstractSyncDataService getService(SyncDatEnum data){
        return (AbstractSyncDataService)SpringUtil.getBean(data.disPoseClass);
    }
/**
 * @description:   根据源类型找到对应的枚举实例
 * @param:
 * @param originalType
 * @return: com.example.deploysinggle.test1.common.enums.SyncDatEnum
 * @author Administrator
 * @date: 2025/1/24 13:31
 */
    public static SyncDatEnum getByOriginalType(String originalType) throws Exception{
        for (SyncDatEnum value : values()) {
            if(value.getTemplateType().equals(originalType)){
                return value;
            }
        }
        throw new BizException(ErrorEnum.SYSTEM_ERROR);
    }
}
